package com.wan.data.mysql.orm.convert.custom;

import com.wan.data.mysql.exception.DBInitializeException;
import com.wan.data.mysql.orm.convert.Converter;
import com.wan.data.mysql.orm.meta.ColumnMeta;
import com.wan.data.mysql.util.DbColumnType;

public class MysqlCharConverter implements Converter {
    @Override
    public DbColumnType getDbType() {
        return DbColumnType.CHAR;
    }

    @Override
    public Object dbToEntity(ColumnMeta columnMeta, Object value) throws Exception {
        return value;
    }

    @Override
    public Object entityToDb(ColumnMeta columnMeta, Object value) throws Exception {
        return value;
    }

    @Override
    public void tryCheck(ColumnMeta columnMeta) throws DBInitializeException {
        if(columnMeta.getFieldType() != String.class){
            throw new DBInitializeException("只能使用String指定mysql的char类型->" + columnMeta);
        }
    }
}
